package net.dgg.rz.production.service;

import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.iboss.base.util.StringUtils;
import net.dgg.rz.common.constant.ModuleCodeConstant;
import net.dgg.rz.common.constant.ScProductConstant;
import net.dgg.rz.common.utils.DataPermissionUtils;
import net.dgg.rz.common.utils.SearchUtils;
import net.dgg.rz.common.utils.ValidateUtils;
import net.dgg.rz.production.dao.ProductOrderDao;
import net.dgg.rz.production.entity.dto.ProcessingOrderDetatilDto;
import net.dgg.rz.production.entity.dto.ProductOrderDetatilDto;
import net.dgg.rz.production.entity.dto.ProductOrderDto;
import net.dgg.rz.production.exception.ProductOrderExcption;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @className ProductDetatilController
 * @Author Quanlin Wan
 * @Description //TODO
 * @Date 2019/4/28 13:52
 **/
@Service
public class ProductDetatilService {
    @Autowired
    ProductOrderDao productOrderDao;
    @Autowired
    SearchUtils searchUtils;
    @Autowired
    DataPermissionUtils dataPermissionUtils;
    @Autowired
    TranslateUtil translateUtil;
    @Autowired
    DesUtil desUtil;

    /**
     * @Author Quanlin Wan
     * @Description //TODO 已放款明细列表数据service
     * @Date 14:57 2019/5/6
     * @Param
     * @return
     **/


    public List<ProductOrderDetatilDto> loanedScProductOrderWithPage(Map params) {
        List<ProductOrderDetatilDto> productOrderDetatilDtos = new ArrayList<>();
        UserEntity userEntity = searchUtils.getcurrUser(params);
        ValidateUtils.strNotEmpty(userEntity, ProductOrderExcption.class, "未获取到登陆人，请重新登录！");
        List<String> statusAttr = new ArrayList<>();
        statusAttr.add(ScProductConstant.RZSCORDER_STATUS17);
        statusAttr.add(ScProductConstant.RZSCORDER_STATUS19);
        statusAttr.add(ScProductConstant.RZSCORDER_STATUS02);
        params.put("statusArr", statusAttr);
        params.put("isLoan", "1");
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_PRODUCT_DETAILED);
        //入参操作
        searchUtils.paramsOperate(params);
        //上面方法排序是使用更新日期正序，这里重新设置排序
        params.put("orderDir", "desc");
        params.put("orderColumn", "t.loan_time");
        productOrderDetatilDtos = productOrderDao.scOrderDetatilWithPage(params);
        //翻译字段
        String[] transColum = {"originCode", "status", "suspendReason"};
        productOrderDetatilDtos = translateUtil.translateList(transColum, productOrderDetatilDtos);
        //隐藏字段
        String[] hideColum = {"customerPhone"};
        productOrderDetatilDtos = desUtil.decryptList(hideColum, productOrderDetatilDtos);
        productOrderDetatilDtos = CustomerNumberEncryptionUtil.encryptionList(hideColum, productOrderDetatilDtos);
        return productOrderDetatilDtos;
    }

    /**
     * @Author Quanlin Wan
     * @Description //TODO 跟进中列表数据service
     * @Date 14:57 2019/5/6
     * @Param
     * @return
     **/

    public List<ProcessingOrderDetatilDto> processingScProductOrderWithPage(Map params) {
        List<ProcessingOrderDetatilDto> processingOrderDetatilDtos = new ArrayList<>();
        UserEntity userEntity = searchUtils.getcurrUser(params);
        ValidateUtils.strNotEmpty(userEntity, ProductOrderExcption.class, "未获取到登陆人，请重新登录！");
        List<String> statusAttr = new ArrayList<>();
        statusAttr.add(ScProductConstant.RZSCORDER_STATUS02);
        params.put("statusArr", statusAttr);
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_PRODUCT_DETAILED);
        //入参操作
        searchUtils.paramsOperate(params);
        //上面方法排序是使用更新日期正序，这里重新设置排序
        params.put("orderDir", "asc");
        params.put("orderColumn", "t.receive_order_date");
        String target = String.valueOf(params.get("target"));
        switch (target){
            case "DYDK":
                params.put("typeCode", ScProductConstant.BUS_YT_DK_DYDK);
                break;
            case "ZJYW":
                params.put("typeCode", ScProductConstant.BUS_YT_DK_ZJYW);
                break;
            case "XYDK":
                params.put("typeCode", ScProductConstant.BUS_YT_DK_XYDK);
                break;
            default:
                params.put("typeCode", ScProductConstant.BUS_YT_DK_DYDK);
                break;
        }
        processingOrderDetatilDtos = productOrderDao.processingDetatilWithPage(params);
        //翻译字段
        String[] transColum = {"originCode", "status", "suspendReason"};
        processingOrderDetatilDtos = translateUtil.translateList(transColum, processingOrderDetatilDtos);
        //隐藏字段
        String[] hideColum = {"customerPhone"};
        processingOrderDetatilDtos = desUtil.decryptList(hideColum, processingOrderDetatilDtos);
        processingOrderDetatilDtos = CustomerNumberEncryptionUtil.encryptionList(hideColum, processingOrderDetatilDtos);
        return processingOrderDetatilDtos;
    }




}
